package com.icss.OA.service.impl;

import com.icss.OA.common.ServiceException;
import com.icss.OA.dao.EmpMapper;
import com.icss.OA.pojo.Emp;
import com.icss.OA.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {

    @Autowired
    EmpMapper mapper;

    @Override
    public List<Emp> findByCondition(Emp condition) {
        return mapper.selectByCond(condition);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(Integer empNo) throws ServiceException {

        int i = mapper.deleteByPrimaryKey(empNo);
        if (i != 1) {
            throw new ServiceException("删除异常");
        }

    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void inertEmp(Emp emp) throws ServiceException {

        int i = mapper.insertSelective(emp);
        if (i != 1) {
            throw new ServiceException("出入异常");
        }

    }

    @Transactional
    @Override
    public void modifyEmp(Emp emp) {

        mapper.updateByPrimaryKeySelective(emp);
    }
}
